import {Injectable} from '@angular/core';
import {CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, CanDeactivate} from '@angular/router';
import {Observable} from 'rxjs';
import {ProductComponent} from "../components/product/product.component";

@Injectable({
  providedIn: 'root'
})
/*离开守卫，提醒未保存ProductComponent的操作*/
export class UnsaveGuard implements CanDeactivate<ProductComponent> {

  canDeactivate(component: ProductComponent, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): Observable<boolean> | Promise<boolean> | boolean {
    return window.confirm("还未保存，确定要离开吗？");
  }

}
